package com.spark.lola.controller;

import com.spark.lola.entity.SupplierToken;
import com.spark.lola.feign.PurReportFeignService;
import com.spark.lola.statistics.request.PurReportDateRequest;
import com.spark.lola.statistics.vo.PurchaseStatisticsVo;
import com.spark.lola.statistics.vo.PurchaseWorkVo;
import com.spark.lola.support.api.entity.TokenUser;
import com.spark.lola.support.common.util.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: DengYeJun
 * @Date: 2020/5/20 17:45
 */
@Api(value = "/api/report/", tags = "报表接口")
@RequestMapping("/api/report/")
@RestController
public class ReportController {
    private static final Logger logger = LoggerFactory.getLogger(ReportController.class);
    @Autowired
    private PurReportFeignService purReportFeignService;

    /**
     * 获取供应商指定期间供应商统计
     */
    @ApiOperation(value = "查询指定期间数据统计")
    @RequestMapping(value = "/statistics",method = RequestMethod.POST)
    ResponseBean supplierStatistics(@RequestBody PurReportDateRequest request,@SessionAttribute SupplierToken tokenUser) {
        PurchaseStatisticsVo vo = new PurchaseStatisticsVo();
        if (tokenUser.getSupplierId() != null) {
            vo = purReportFeignService.supplierStatistics(tokenUser.getSupplierId(), request.getStart(), request.getEnd());
        }
        return ResponseBean.success(vo);
    }

    /**
     * 供应商待处理业务
     */
    @ApiOperation(value = "查询供应商待处理业务")
    @RequestMapping(value = "/work",method = RequestMethod.POST)
    ResponseBean supplierWork(@SessionAttribute SupplierToken tokenUser){
        PurchaseWorkVo vo= purReportFeignService.supplierWork(tokenUser.getSupplierId());
        return ResponseBean.success(vo);
    }

}
